<%@ page import="com.ws.q1.conifg.Res" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户信息列表</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath}/js/jquery-2.1.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
    <style>
        .cus-container {
            width: 1368px;
        }
        #user-add .modal-content {
            padding: 0 20px 20px;
        }
        #user-edit .modal-content {
            padding: 0 20px 20px;
        }
        .pagination-container {
            margin-top: 20px;
        }
        .pagination-container a, .pagination-container span {
            margin: 0 5px;
        }
        .pagination-container a {
            text-decoration: none;
            color: #007bff;
        }
        .pagination-container span {
            font-weight: bold;
        }
    </style>
</head>
<body>
<div class="container cus-container">
    <h3 class="text-center">用户信息列表</h3>
    <div>
        <!-- 搜索框div -->
        <div id="search-user" style="float: left; margin: 10px 0px;">
            <form class="form-inline" action="${pageContext.request.contextPath}/houtaiuser/list" method="get">
                <div class="form-group">
                    <label for="exampleInputName2">用户名</label>
                    <input type="text" name="name" value="${param.name}" class="form-control" id="exampleInputName2">
                </div>
                <button type="submit" class="btn btn-default">查询</button>
                <button type="button" class="btn btn-default" onclick="clearSearch()">清空</button>
            </form>
        </div>

        <!-- 添加、删除的按钮 -->
        <div style="float: right; margin: 10px 0px;">
            <a href="${pageContext.request.contextPath}/houtaiuser/tiao" class="btn btn-primary">增加</a>
        </div>
    </div>
    <table class="table table-striped table-hover">
        <thead class="table-dark">
        <tr>
            <th>id</th>
            <th>用户名</th>
            <th>手机号</th>
            <th>头像</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${list}" var="user">
            <tr>
                <td>${user.id}</td>
                <td>${user.name}</td>
                <td>${user.phone}</td>
                <td><img class="user-avatar" src="<%=Res.fileUrl%>${user.tou}" width="50" height="50" alt="用户头像"></td>
                <td>
                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/user/role">分配角色</a>
                    <a href="${pageContext.request.contextPath}/houtaiuser/delete?id=${user.id}" class="btn btn-danger">删除</a>
                    <a href="${pageContext.request.contextPath}/houtaiuser/huixian?id=${user.id}" class="btn btn-primary">修改</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

    <!-- 分页导航 -->
    <nav aria-label="Page navigation">
        <ul class="pagination pagination-sm justify-content-center">
            <!-- 上一页 -->
            <li class="page-item ${pageInfo.pageNum == 1 ? 'disabled' : ''}">
                <a class="page-link" href="?currentPage=${pageInfo.pageNum - 1}&name=${user}" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                </a>
            </li>
            <!-- 页码 -->
            <c:forEach begin="${startPage}" end="${endPage}" var="i">
                <li class="page-item ${i == pageInfo.pageNum ? 'active' : ''}">
                    <a class="page-link" href="?currentPage=${i}&name=${param.name}">${i}</a>
                </li>
            </c:forEach>
            <!-- 下一页 -->
            <li class="page-item ${pageInfo.pageNum == pageInfo.pages ? 'disabled' : ''}">
                <a class="page-link" href="?currentPage=${pageInfo.pageNum + 1}&name=${user}" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>
        </ul>
    </nav>
</div>
<script>
    // 清空搜索框
    function clearSearch() {
        document.getElementById('exampleInputName2').value = '';
        document.forms[0].submit();
    }
</script>
</body>
</html>
